package com.lwy.goods.controller;

import com.github.pagehelper.PageInfo;
import com.lwy.common.Result;
import com.lwy.common.StatusCode;
import com.lwy.goods.pojo.TbAd;
import com.lwy.goods.service.impl.TbAdServiceImpl;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;

//商品controller控制层
@RestController
@RequestMapping("ad")
public class TbAdController {


    @Resource
    TbAdServiceImpl tbAdService;

    //分页查询列表
    @RequestMapping("list")
    public Result<PageInfo<TbAd>> list(String name,Integer pageNum, Integer pageSize){
        PageInfo<TbAd> page = tbAdService.page(name,pageNum, pageSize);
        return new Result<PageInfo<TbAd>>(true, StatusCode.OK,"查询",page);
    }

    @RequestMapping("save")
    public Result<List<TbAd>> save(TbAd tbAd) throws ParseException {
        int save = tbAdService.saveTbAd(tbAd);
        return new Result<List<TbAd>>(true, StatusCode.OK,"新增",save);
    }

    @RequestMapping("edit")
    public Result<List<TbAd>> edit(TbAd tbAd) throws ParseException {
        int update = tbAdService.updateTbAd(tbAd);
        return new Result<List<TbAd>>(true, StatusCode.OK,"编辑",update);
    }
    @RequestMapping("findId")
    public TbAd findId(Integer id){
        return tbAdService.getById(id);
    }

    @RequestMapping("del")
    public Result<List<TbAd>> del(Integer id){
        boolean del = tbAdService.removeById(id);
        return new Result<List<TbAd>>(true, StatusCode.OK,"删除",del);
    }
}
